<template>
<view class="container">
	<view class="avatar">
	    <image :src="avatar"></image>
	</view>
	<view class="view_input1">
	    <view class="view_input_title2">真实姓名:</view>
		<input class="view_input_input1" type="text" v-model="form.realname"
		placeholder-class="placeholderClass" placeholder="请输入姓名"/>
	</view>
	<view class="view_input1">
	    <view class="view_input_title2">出生日期:</view>
		<picker mode="date" class="view_input_input1" 
		:value="form.birthDay" 
		@change="bindBirth">
		    {{form.birthDay}}
		</picker>
	</view>
	<view class="view_input1">
	    <view class="view_input_title2">性&nbsp;&nbsp;&nbsp;&nbsp;别:</view>
		<radio-group @change="bindSex" class="view_input_radio1" data-name="sex">
			<label>
				<radio value="男" :checked="form.sex == '男'"/>
				<view>男</view>
			</label>
			<label style="margin-left: 40rpx;">
				<radio value="女" :checked="form.sex == '女'"/>
				<view>女</view>
			</label>
		</radio-group>
	</view>
	<view class="view_input1">
	    <view class="view_input_title2">学&nbsp;&nbsp;&nbsp;&nbsp;历:</view>
		<picker @change="bindEdu" :value="educationIndex" :range="education"
		class="view_input_input1">
			<view>{{education[educationIndex]}}</view>
		</picker>
	</view>
	
	<view class="view_input1">
	    <view class="view_input_title2">工作状态:</view>
		<radio-group @change="bindType" class="view_input_radio1">
			<label>
				<radio value="在职" :checked="form.workType == '在职'"/>
				<view>在职</view>
			</label>
			<label style="margin-left: 40rpx;">
				<radio value="离职" :checked="form.workType == '离职'"/>
				<view>离职</view>
			</label>
		</radio-group>
	</view>
	
	<view class="view_input1">
	    <view class="view_input_title2">工作年限:</view>
		<picker @change="bindWorkTime" :value="workTimeIndex" :range="workTime"
		class="view_input_input1">
			<view>{{form.workTime}}</view>
		</picker>
	</view>
	
	<view class="view_input1">
	    <view class="view_input_title2">期望薪资:</view>
		<input class="view_input_input1" type="text" v-model="form.money"
		placeholder-class="placeholderClass" placeholder="请输入薪资"/>
	</view>
	
	<view class="view_input1" style="align-items: center;">
	    <view class="view_input_title2">工作城市:</view>
		<input class="view_input_input1" type="text" style="width:50%;" @click="jumpCity"
		:value="form.city ? form.city : '请选择'" disabled/>
		<image @click="jumpCity" style="width:35rpx;height:35rpx;" src="/static/img/right.png"></image>
	</view>
	
	<view class="view_input1" style="align-items: center;">
	    <view class="view_input_title2">工作岗位:</view>
		<input class="view_input_input1" type="text" style="width:50%;" @click="jumpJob"
		:value="form.post ? form.post : '请选择'" disabled/>
		<image @click="jumpJob" style="width:35rpx;height:35rpx;" src="/static/img/right.png"></image>
	</view>
	
	<view class="view_input1" style="align-items: center;">
	    <view class="view_input_title2">培训专业:</view>
		<input class="view_input_input1" type="text" style="width:50%;" @click="jumpBus"
		:value="form.business ? form.business : '请选择'" disabled/>
		<image @click="jumpBus" style="width:35rpx;height:35rpx;" src="/static/img/right.png"></image>
	</view>
	
	<view class="view_input1" style="align-items: center;">
	    <view class="view_input_title2">培训经历:</view>
		<input class="view_input_input1" type="text" style="width:50%;" @click="jumpStudy"
		:value="form.studyList ? form.studyList : '请选择'" disabled/>
		<image @click="jumpStudy" style="width:35rpx;height:35rpx;" src="/static/img/right.png"></image>
	</view>
	
	<view class="view_else">
		<view class="view_input_title2">工作经历:</view>
	</view>
	<view class="view_textarea">
		<textarea auto-height maxlength="-1"
		placeholder="工作经历" v-model="form.workList"/>
	</view>
	
	<view class="view_else">
		<view class="view_input_title2">个人特长:</view>
	</view>
	<view class="view_textarea">
		<textarea auto-height maxlength="-1"
		placeholder="个人特长" v-model="form.advantage"/>
	</view>
	
	
	<view class="view_else">
		<view class="view_input_title2">上传头像:</view>
	</view>
	<view class="view_img">
		<image class="uploadImg" v-if="form.realPic" @click="upLoad" :src="imgUrl + form.realPic"></image>
		<image class="uploadImg" v-else @click="upLoad" :src="pubImg"></image>
	</view>
	<view style="height:120rpx;"></view>
	<button v-if="submittrue"  @click="addInfo" class="buttonClass">提交</button>
</view>
</template>

<script>
import request from '@/util/request.js'
export default {
	data() {
		return {
			imgUrl:this.url,
			submittrue:true,
			pubImg:'/static/img/pub.png',
			avatar:uni.getStorageSync('avatarUrl'),
			form:{realPic:''},
			educationIndex:0,
			education:['高中以下','中专','大专','本科','硕士以上'],
			workTime: ['无', '1年', '2年', '3年','4年','5年以上'],
			workTimeIndex:0
		}
	},
	onLoad:function(){
		this.getInfo()
	},
	methods: {
		getInfo:function(){
			var that = this;
			var data = {uid:uni.getStorageSync('uid')}
			request({
				url: 'user/info',
				method: 'get',
				data:data,
				success: (res) => {
					that.form = res.data.data
				},
			})
		},
		addInfo:function(){
			var array = {
				'realname':'姓名必填',
				'sex':'性别必选',
				'workType':'工作状态必填',
				'post':'期望工作岗位必填',
				'money':'期望工作薪资',
				'business':'培训专业必选',
				'city':'期望工作城市必选',
				'studyList':'培训经历必选',
				'birthDay':'选择出生日期'
			}
			for(var x in array){
			    if(!this.form[x]){
			        uni.showToast({
			        	title:array[x],
			        	icon: "none", 
			        	position:'bottom',
			        });
			        return;
			    }
			}
			this.submittrue = false
			//调接口 提交
			var that = this
			request({
				url: 'user/edit',
				method: 'put',
				data:this.form,
				success: (res) => {
					uni.showToast({
						title:res.data.msg,
						icon: 'none',
						duration: 2000,
						success() {
							setTimeout(function() {
								uni.navigateBack();
							}, 2000);
						}
					})
				}
			})
		},
		upLoad:function(){
			var token = 'tymy';
			var that = this
			uni.chooseImage({
				count: 1,
				sizeType:['copressed'],
				success(res){
					uni.showLoading({
					    title: '上传中'
					});
					//因为有一张图片， 输出下标[0]， 直接输出地址
					var imgFiles = res.tempFilePaths[0]
					var uper = uni.uploadFile({
						// 需要上传的地址
						url:that.imgUrl+'/api/app/upload',
						// filePath  需要上传的文件
						filePath: imgFiles,
						name:'img',
						header: {
						    // "Content-Type": "multipart/form-data",
						    // 'accept': 'application/json',  //若有token，此处换上你的token，没有的话省略
							'Authorization' : 'Bearer' + token
						},
						formData:{
							//name:'img'
						},
						success(res1) {
							uni.hideLoading();
							// 显示上传信息
							that.form.realPic = res1.data
						}
					});
				}
			})
		},
		bindSex:function(e){
			this.form.sex = e.detail.value
		},
		bindBirth:function(e){
			this.form.birthDay = e.detail.value
		},
		bindEdu:function(e){
			this.educationIndex = e.detail.value
			this.form.education = this.education[e.detail.value]
		},
		bindType:function(e){
			this.form.workType = e.detail.value
		},
		bindWorkTime:function(e){
			this.workTimeIndex = e.detail.value
			this.form.workTime = this.workTime[e.detail.value]
		},
		jumpCity:function(){
			var url = '/pages/city/index'
			uni.navigateTo({
				url:url
			});
		},
		jumpJob:function(){
			var url = '/pages/login/post/index?post='+this.form.post
			uni.navigateTo({
				url:url
			});
		},
		jumpBus:function(){
			var url = './business?key='+this.form.business
			uni.navigateTo({
				url:url
			});
		},
		jumpStudy:function(){
			var url = './study?key='+this.form.studyList
			uni.navigateTo({
				url:url
			});
		}
	}
}
</script>
<style>
.avatar{background: #ff861a;width:100%;height:100px;display: flex;justify-content:center;}
.avatar image{width:80px;height:80px;border-radius: 50%;margin-top:10px;}
.red{color:red;}
.remark{
	width:100%;display: flex;
    justify-content: center;height:30rpx;
	font-size:14px;
}
.view_input_radio1{
	display: flex;
	flex-direction: row;
	height:70rpx;
	line-height: 70rpx;
	width:65%;
}
.view_input_radio1 label{
	display: flex;
	flex-direction: row;
	height:70rpx;
	line-height: 70rpx;
}
.view_else{
	width:100%;
	display: flex;
	flex-direction: row;
	height:70rpx;
	line-height: 70rpx;
}
.view_img{
	padding:20rpx 20rpx 20rpx 30rpx;
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
}
.uploadImg{
	width:200rpx;
	height:180rpx;
	border:1px dashed #CCCCCC;
	margin-right:15rpx;
}
.view_textarea{
	width:100%;
	padding:15rpx 15rpx 15rpx 15rpx;
}
.view_textarea textarea {
	width:93%;
	border:1px dashed #CCCCCC;
	min-height:200rpx;
	padding:10rpx 10rpx 10rpx 10rpx;
}
</style>